<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-module-add">
			<input id="treeId" name="parentId" type="hidden" th:value="${parentId}"   />
			<div class="form-group">
				<label class="col-sm-3 control-label ">所属项目：</label>
				<div class="col-sm-8">
					<select name="projectId" th:with="type=${projects}">
						<option th:each="project : ${type}" th:text="${project.projectName}" th:value="${project.projectId}" th:selected="${project.projectId==projectId}? 'selected' : 'false'"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label ">上级模块：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" id="parentName" readonly="true" th:value="${parentName}"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">模块名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="moduleName" id="moduleName">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">显示排序：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="orderNum">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">访问路径：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="moduleUrl" placeholder="前缀URL">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">模块状态：</label>
				<div class="col-sm-8">
				    <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
						<input type="radio" th:id="${dict.dictId}" name="status" th:value="${dict.dictValue}" th:checked="${dict.isDefault == 'Y' ? true : false}">
						<label th:for="${dict.dictId}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" class="form-control" type="text">
				</div>
			</div>
		</form>
	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript">
		var prefix = ctx + "system/module";
		
		$("#form-module-add").validate({
			rules:{
				moduleName:{
					required:true,
					remote: {
		                url: prefix + "/checkModuleNameUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"parentId": function() {
		                		return $("input[name='parentId']").val();
		                    },
		                	"moduleName" : function() {
		                        return $.common.trim($("#moduleName").val());
		                    }
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},
				orderNum:{
					required:true,
					digits:true
				},
			},
			messages: {
		        "moduleName": {
		            remote: "模块已经存在"
		        }
		    }
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save(prefix + "/add", $('#form-module-add').serialize());
	        }
	    }
	</script>
</body>
</html>
